﻿using System;
using System.Data;
using System.Collections.Generic;
using Gmis.Model;
using Gmis.DalFactory;
using Gmis.IDAL;
namespace Gmis.BLL
{
    /// <summary>
    /// FAccount
    /// </summary>
    public partial class FAccount
    {
        private readonly IFAccount dal = DataAccess.CreateFAccount();
        public FAccount()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string sId)
        {
            return dal.Exists(sId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Gmis.Model.FAccount model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Gmis.Model.FAccount model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string sId)
        {

            return dal.Delete(sId);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string sIdlist)
        {
            return dal.DeleteList(sIdlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gmis.Model.FAccount GetModel(string sId)
        {

            return dal.GetModel(sId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Gmis.Model.FAccount> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Gmis.Model.FAccount> DataTableToList(DataTable dt)
        {
            List<Gmis.Model.FAccount> modelList = new List<Gmis.Model.FAccount>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Gmis.Model.FAccount model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Gmis.Model.FAccount();
                    if (dt.Rows[n]["sId"] != null && dt.Rows[n]["sId"].ToString() != "")
                    {
                        model.sId = dt.Rows[n]["sId"].ToString();
                    }
                    if (dt.Rows[n]["sType"] != null && dt.Rows[n]["sType"].ToString() != "")
                    {
                        model.sType = dt.Rows[n]["sType"].ToString();
                    }
                    if (dt.Rows[n]["sItem"] != null && dt.Rows[n]["sItem"].ToString() != "")
                    {
                        model.sItem = dt.Rows[n]["sItem"].ToString();
                    }
                    if (dt.Rows[n]["cAmount"] != null && dt.Rows[n]["cAmount"].ToString() != "")
                    {
                        model.cAmount = decimal.Parse(dt.Rows[n]["cAmount"].ToString());
                    }
                    if (dt.Rows[n]["sOperator"] != null && dt.Rows[n]["sOperator"].ToString() != "")
                    {
                        model.sOperator = dt.Rows[n]["sOperator"].ToString();
                    }
                    if (dt.Rows[n]["dCreateDate"] != null && dt.Rows[n]["dCreateDate"].ToString() != "")
                    {
                        model.dCreateDate = DateTime.Parse(dt.Rows[n]["dCreateDate"].ToString());
                    }
                    if (dt.Rows[n]["sComment"] != null && dt.Rows[n]["sComment"].ToString() != "")
                    {
                        model.sComment = dt.Rows[n]["sComment"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

